package org.restly.core;

import org.restly.servlet.RestlyHttpServletResponse;
import org.restly.Interceptor;
import org.restly.Representation;

import java.util.Iterator;
import java.util.List;

/**
 * Oct 25, 2008, 5:56:08 AM
 *
 * @author <a href="http://restly.org/">Erik Beeson</a>
 */
public class InterceptorChain {
	private Iterator<Interceptor> iterator;

	public InterceptorChain(List<Interceptor> interceptors) {
		this.iterator = interceptors.iterator();
	}

	public Representation next(org.restly.servlet.RestlyHttpServletRequest request, RestlyHttpServletResponse response) {
		if(iterator.hasNext()) {
			return iterator.next().before(request, response, this);
		} else {
			return null;
		}
	}
}
